//
// Created by xili on 2024/9/4 20:02.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution1 {
public:
    int countWays(vector<int> &nums) {
        int n = nums.size();
        ranges::sort(nums);
        int ans = 0;
        for (int k = 0; k <= n; k++) {
            if (k > 0 && nums[k - 1] >= k) {
                continue;
            }
            if (k < n && nums[k] <= k) {
                continue;
            }
            ans++;
        }
        return ans;
    }
};

class Solution2 {
public:
    int countWays(vector<int> &nums) {
        std::sort(nums.begin(), nums.end());
        int ans = nums[0] > 0;
        for (int i = 1; i < nums.size(); i++) {
            ans += nums[i - 1] < i && nums[i] > i;
        }

        return ans + 1;
    }
};